﻿
using DE_MVC_WyFy.Areas.Administrator.Models;
using DE_MVC_WyFy.Areas.Administrator.Models.Enities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;


namespace DE_MVC_WyFy.Areas.Administrator.Controllers
{
	public class ProductTypeManagerController : Controller
	{
		//
		// GET: /Administrator/ProductType/
		IEnumerable<ProductType> db;
		public ActionResult Index()
		{

			db = ProductType.Objects.All();
			return View(db);
		}
		public ActionResult Detail(int id)
		{
			ProductType prodType = ProductType.Objects.GetById(id);
			return View(prodType);
		}
		public ActionResult Edit(int id)
		{
			ProductType prodType = ProductType.Objects.GetById(id);
			ViewBag.ProductTypeID = new SelectList(ProductType.Objects.All(), "ProductTypeID", "ProductTypeName", prodType.Parent);
			ViewBag.IDCategory = new SelectList(Category.Objects.All(), "ID", "Name", prodType.IDCategory);
			return View(prodType);
		}
		[HttpPost]
		public ActionResult Edit(ProductType prodType)
		{
			if (ModelState.IsValid)
			{
				ProductType.Objects.Update(prodType);
				return RedirectToAction("Index");
			}
			//ViewBag.ProductTypeID = new SelectList(ProductType.Objects.All(), "ProductTypeID", "ProductTypeName", prodType.ProductTypeID);
			//ViewBag.ID = new SelectList(Category.Objects.All(), "ID", "Name", prodType.IDCategory);
			return View(prodType);
		}
		public ActionResult Create(ProductType prodType)
		{
			return View(prodType);
		}

	}
}
